package org.eclipse.epsilon.emc.rdbms.core.sqlstatement;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.eclipse.epsilon.emc.rdbms.core.persistancebroker.PersistanceBroker;
import org.eclipse.epsilon.emc.rdbms.core.persistancemechanism.RelationalDatabase;



public  class DeleteSQLStatement extends SQLStatement
{
	/** This method is to generate the SQL Statement to delete an element from the database
	*@param tableInfo - The resultset containing the database,schema and table information
	*@param criteria  - This is the hashmap of attributes and values that will be specified in the where clause.
	*@return statement - This is the generated SQL Statement to delete the object from the database
	*/	
	@Override
	public String BuildForCriteria(ResultSet tableInfo,HashMap<String, Object> criteria) throws SQLException 
	{
		RelationalDatabase connection = PersistanceBroker.connectTo();
		while (tableInfo.next())
		{
			databaseName = tableInfo.getString("TABLE_CAT");
			schemaName = tableInfo.getString("TABLE_SCHEMA");
			tableName = tableInfo.getString("TABLE_NAME");	
		}
		
		String  statement = "";
 		statement = connection.getClauseStringDelete()+databaseName+"."+schemaName+"."+tableName;
 		if(criteria !=null)
 		{
 			if(criteria.size()>0)
 			{
 				statement = statement + " WHERE "+getStringFromHashMap(criteria,"AND");
 			}
 		} 		
 		return statement;
	}

	/** This is not implemented
	*/	
	@Override
	public String BuildForCriteria(ResultSet sqlTables, HashMap properties,HashMap<String, Object> props) 
	{
		return null;
	}

	/** This is not implemented
	*/	

	@Override
	public String BuildForCriteria(ResultSet sqlTables,ArrayList<String> properties, HashMap<String, Object> props) 
	{	
		return null;
	}

	/** This is not implemented
	*/	
	
	@Override
	public String BuildForCriteria(ResultSet tableInfo, ResultSet sqlColumns,
			ResultSet primaryKey, ResultSet columnMetaData,
			HashMap<String, Object> properties) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
	/** This is not implemented
	*/	

	@Override
	public String BuildForCriteria(ResultSet sqlTables,
			ArrayList<String> columns, ArrayList PKtables, ArrayList FKtables,
			ArrayList PKcols, ArrayList FKcols,
			HashMap<String, Object> parameters) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
		}



